//
//  ZXFDWWCView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/19.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ZXFDWWCView.h"
#define CellSP 20*fw
#define CellW 80*fw
@interface ZXFDWWCView (){
    
}

@property (strong, nonatomic) NSMutableArray *dataArr;

@property (strong, nonatomic) SYNoLabel *nolab;
@end

@implementation ZXFDWWCView

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Register cell classes
    [self.collectionView registerClass:[ZXFDWWCCell class] forCellWithReuseIdentifier:reuseIdentifier];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    _nolab = [[SYNoLabel alloc] initWithNameStr:@"" contView:self.view];
}
- (void)requestData:(NSMutableArray *)dataListArr {
    self.dataArr = dataListArr;
    if (dataListArr.count == 0) {
        //TOP
                self.collectionView.hidden = YES;
//
        self.nolab.hidden = NO;
    } else {
         self.collectionView.hidden = NO;
        self.nolab.hidden = YES;
    }
    
    [self.collectionView reloadData];
}
#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
//    return 1;
//TOP
    return self.dataArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ZXFDWWCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    // Configure the cell
    //TOP
    SYZaiXianFuDaoModel *zxfd = self.dataArr[indexPath.row];
    cell.titleLabel.text = zxfd.title;
    NSString *imageNameStr = nil;
    if ([zxfd.tutorType integerValue] == 0) {
        //互动课堂
        imageNameStr = @"fudao_weiwancheng_banban";
    } else if ([zxfd.tutorType integerValue] == 1) {
        //群聊
        imageNameStr = @"fudao_weiwancheng_qunliao";
    } else {
        //单聊
        imageNameStr = @"fudao_weiwancheng_danliao";
    }
    cell.typeImageView.image = [UIImage imageNamed:imageNameStr];
    NSString *typeName = SYStringWithPickFormat(@"辅导类型：", zxfd.typeName);
    cell.fuDaoLeiXingLabel.attributedText = [PublickFunctionObject getPriceAttribute:typeName and:[UIColor redColor] andChangeBenginString:@"：" andEndString:@"" andSize:12];
    NSString *accountName = SYStringWithPickFormat(@"班级名称：", zxfd.className);
//    cell.mentorLabel.attributedText = [PublickFunctionObject getPriceAttribute:accountName and:[UIColor redColor] andChangeBenginString:@"：" andEndString:@"" andSize:12];
    cell.mentorLabel.text = accountName;
    
    cell.jieZhiRiQiLabel.text = SYStringWithPickFormat(@"截止日期：", zxfd.endDate);
    cell.fuDaoCeShuLabel.text = SYStringWithPickFormat(@"辅导次数：", zxfd.tutorTimes);
    NSString *stuStr = SYStringWithPickFormat(@"学生数量：", zxfd.studentNums);//缺少学生数量。接口
    cell.xueShengNumLabel.attributedText = [PublickFunctionObject getPriceAttribute:stuStr and:[UIColor redColor] andChangeBenginString:@"：" andEndString:@"" andSize:12];
    cell.keMuLable.text = SYStringWithPickFormat(@"完成日期：", zxfd.createDate);
    
    cell.block = ^(WeiWanChengType type) {
        SYZaiXianFuDaoModel *zaiModel = [[SYZaiXianFuDaoModel alloc] init];
        zaiModel = zxfd;
        if (type == WeiWanChengTypeDelete) {//删除
            zaiModel.tutorType = @"100";
        } else {
            zaiModel.tutorType = @"101";
        }
        
        [self.delegate LeaveForClassDetailView:zaiModel];
    };
    
    return cell;
}
#pragma mark == collectionViewDelegate
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    //top, left, bottom, right
    return CGSizeMake(318*fw, 178*fh);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    //top, left, bottom, right
    if (_Type == YES) {
        return UIEdgeInsetsMake(20, CellSP, 20,CellSP);
    }else{
        return UIEdgeInsetsMake(CellSP, CellW, CellSP,CellW);
    }
}
#pragma mark <UICollectionViewDelegate>

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
     SYZaiXianFuDaoModel *zxfd = self.dataArr[indexPath.row];
    [self.delegate LeaveForClassDetailView:zxfd];
}

@end
